/*
 * @Description: 是否继续接单底部小部件 OrderTakingOperationWidget
 * @version: 
 * @Company: 
 * @Author: ZhengZhuang
 * @Date: 2019-08-29 09:32:43
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-01-27 17:39:49
 */
import 'dart:io';

// import 'package:baidu_face/baidu_face.dart';
// import 'package:baidu_face/config.dart';
// import 'package:baidu_face/enums.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/event/event_bus.dart';
import 'package:C20Driver/model/plice_model.dart';
import 'package:C20Driver/provider/driver_information.dart';
import 'package:C20Driver/provider/order_information.dart';
import 'package:C20Driver/service/mqtt_manage.dart';
import 'package:C20Driver/service/request.dart';
import 'package:C20Driver/utils/toast.dart';
import 'package:C20Driver/utils/utils.dart';
import 'package:C20Driver/routers/navigator_util.dart';
import 'package:provider/provider.dart';

class OrderTakingOperationWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: ScreenUtil().setWidth(750.0),
      height: ScreenUtil().setWidth(140.0),
      padding: EdgeInsets.only(
        left: ScreenUtil().setWidth(20.0),
        right: ScreenUtil().setWidth(20.0),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          MaterialButton(
            minWidth: ScreenUtil().setWidth(150.0),
            height: ScreenUtil().setWidth(100.0),
            child: Text(
              '收车',
              style: TextStyle(
                fontSize: ScreenUtil().setSp(30.0),
                color: Colors.white,
              ),
            ),
            color: Color.fromARGB(255, 89, 90, 108),
            onPressed: () {
              Utils.setWorkimgStatus(context);
              eventBus.fire(new SetDispatchOrderList());
              Navigator.of(context).popUntil(ModalRoute.withName("/indexPage"));
              Provider.of<DriverInformation>(context, listen: false)
                  .setNeedNewFace('0');
            },
          ),
          MaterialButton(
              minWidth: ScreenUtil().setWidth(520.0),
              height: ScreenUtil().setWidth(100.0),
              child: Text(
                '完成，继续接单',
                style: TextStyle(
                  fontSize: ScreenUtil().setSp(36.0),
                  color: Colors.white,
                ),
              ),
              color: Color.fromARGB(255, 255, 153, 0),
              onPressed: () {
                if (Provider.of<DriverInformation>(context, listen: false)
                        .needNewFace ==
                    '1') {
                  _baiduCheak(context);
                } else {
                  // Utils.setWorkimgStatus(context),
                  MqttManage.getInstance().driverOnline(context, "on");
                  eventBus.fire(new SetDispatchOrderList());
                  Navigator.of(context)
                      .popUntil(ModalRoute.withName("/indexPage"));
                }
              })
        ],
      ),
    );
  }

  //百度重新扫脸
  void _baiduCheak(BuildContext context) async {
    //   DriverInformation provider =
    //       Provider.of<DriverInformation>(context, listen: false);
    //   final config = Config(
    //     livenessTypeList: [LivenessType.Eye],
    //   );
    //   if (Platform.isAndroid) {
    //     await BaiduFace.instance.init('driver-01-face-android', config: config);
    //   } else if (Platform.isIOS) {
    //     await BaiduFace.instance.init('driver-03-face-ios', config: config);
    //   }
    //   final base64Image = await BaiduFace.instance.liveDetect();
    //   var data = await Request.submitFaceRecognition(base64Image,
    //       provider.driverInfo.idNo, provider.driverInfo.driverName, '1');
    //   if (data['error_msg'] == 'SUCCESS') {
    //     PliceModel mod = PliceModel.fromJson(data);
    //     if (mod.result.score >= double.parse(provider.threshold)) {
    //       BaiduFace.instance.uninitCollect();

    //       eventBus.fire(new SetDispatchOrderList());
    //       Navigator.of(context).popUntil(ModalRoute.withName("/indexPage"));

    //       Provider.of<DriverInformation>(context, listen: false)
    //           .setNeedNewFace('0');
    //       MqttManage.getInstance().driverOnline(context, "on");
    //     } else {
    //       ToastX.center('人脸识别失败，相似度太低');
    //       Request.closeReceivingOrder(context);
    //     }
    //   } else {
    //     ToastX.center('人脸识别失败');
    //     Request.closeReceivingOrder(context);
    //   }
  }
}
